var BSTYUN = BSTYUN || {};
BSTYUN.homepage = {
    init: function() {
        var that = this;
        //判断访问设备
        //that.checkIsPhone();
        /*轮播图*/
        that.showBanner();
        /*套餐、产品跳转*/
        that.sendRedirect();
    },
    checkIsPhone: function(){
    	if (!Array.prototype.indexOf)
    	{
    	  Array.prototype.indexOf = function(elt /*, from*/)
    	  {
    	    var len = this.length >>> 0;
    	    var from = Number(arguments[1]) || 0;
    	    from = (from < 0)
    	         ? Math.ceil(from)
    	         : Math.floor(from);
    	    if (from < 0)
    	      from += len;
    	    for (; from < len; from++)
    	    {
    	      if (from in this &&
    	          this[from] === elt)
    	        return from;
    	    }
    	    return -1;
    	  };
    	};
    	var checkPhone = function(){
	        var ua = navigator.userAgent.toLowerCase(),
	            reg = /iPhone|iPad|Android|ucweb|windows\s+mobile|Windows\s+Phone/i;
	            return reg.test(ua);
	    };
	    if( checkPhone() ){
	    	var url = location.href,
	    		isReturn = url.substring( url.indexOf("_usingPcVersion")+16 ) ;
	    	alert(isReturn)
	    	if( isReturn == "true" ){
	    		//访问电脑版
		    	return;
		    }else{
		    	location.href="http://m.bstyun.com";
		    };
	    };
    },
    showBanner:function () {
        var $slide = $("#index-slide"),
            $li = $slide.find('li');
        if($li.length==1){
            $slide.find('.trigger-box').hide();
        }
        slideShow(0);
        $slide.switchable({
            triggers: $slide.find('.trigger-box'),
            panels: 'li',
            effect: 'fade',
            interval: 5,    //自动播放间隔，单位是秒。默认值即3000毫秒。
            autoplay: true, //自动播放
            beforeSwitch: function(e, i){
                slideShow(i);
            }
        });

        function slideShow(index){
            var _li = $li.eq(index),
                _img = _li.data('img');
            if(_img != 'none' && _img != undefined){
                _li.css('background-image','url('+_img+')').data('img','none');
            }
        }
    },
    sendRedirect:function(){
    	var $box = $('.product_con');
    	$box.on('click','li',function(){
    		var href = $(this).find('.y-btn').attr('href');
    		location.href = href;
    	});
    }
};
$(function() {
    /*初始化*/
    BSTYUN.homepage.init();
    /**第一DIV切换**/
    $("#div2,#div1").mouseover(function(){
        if(div1.style.display=='none'){
                div1.style.display='block';
                div2.style.display='none';
            }else{
                div2.style.display='block';
                div1.style.display='none';
        }
    });
    $("#div1,#div2").mouseout(function(){
        if(div1.style.display=='none'){
                div1.style.display='block';
                div2.style.display='none';
            }else{
                div2.style.display='block';
                div1.style.display='none';
        }
    });

    /**第二DIV切换**/
    $("#div4,#div3").mouseover(function(){
        if(div3.style.display=='none'){
                div3.style.display='block';
                div4.style.display='none';
            }else{
                div4.style.display='block';
                div3.style.display='none';
        }
    });
    $("#div3,#div4").mouseout(function(){
    
        if(div3.style.display=='none'){
                div3.style.display='block';
                div4.style.display='none';
            }else{
                div4.style.display='block';
                div3.style.display='none';
        }
    });
    
        /**第三DIV切换**/
    $("#div6,#div5").mouseover(function(){
        if(div5.style.display=='none'){
                div5.style.display='block';
                div6.style.display='none';
            }else{
                div6.style.display='block';
                div5.style.display='none';
        }
    });
    $("#div5,#div6").mouseout(function(){
    
        if(div5.style.display=='none'){
                div5.style.display='block';
                div6.style.display='none';
            }else{
                div6.style.display='block';
                div5.style.display='none';
        }
    });
    
        /**第四DIV切换**/
    $("#div8,#div7").mouseover(function(){
        if(div7.style.display=='none'){
                div7.style.display='block';
                div8.style.display='none';
            }else{
                div8.style.display='block';
                div7.style.display='none';
        }
    });
    $("#div7,#div8").mouseout(function(){
    
        if(div7.style.display=='none'){
                div7.style.display='block';
                div8.style.display='none';
            }else{
                div8.style.display='block';
                div7.style.display='none';
        }
    });
});